package com.designpattern.strategy;

import java.util.Arrays;

/**
 * 策略模式：
 */
public class Main {
    public static void main(String[] args) {
//        int[] arr ={1,3,5,6,2,3,6,12,55,13,4,6};
//        Sorter sorter = new Sorter();
//        sorter.sort(arr);
//        System.out.println(Arrays.toString(arr));

//        Cat[] arr = {new Cat(3, 3), new Cat(5, 5), new Cat(1, 1)};
//        Sorter sorter = new Sorter();
//        sorter.sort(arr);
//        System.out.println(Arrays.toString(arr));

//        Dog[] arr = {new Dog(3), new Dog(5), new Dog( 1)};
//        Sorter sorter = new Sorter();
//        sorter.sort(arr);
//        System.out.println(Arrays.toString(arr));

        Dog[] arr = {new Dog(3), new Dog(5), new Dog(1)};
        Sorter2<Dog> sorter = new Sorter2<>();
        sorter.sort(arr, new DogComparator());
        sorter.sort(arr, ( o1, o2) -> {
            if (o1.food < o2.food) return -1;
            else if (o1.food > o2.food) return 1;
             return 0;
        });
        System.out.println(Arrays.toString(arr));
    }
}
